package com.xykj.mapper;

import com.xykj.common.entry.ChinaIndex;
import com.xykj.common.entry.NewsFlash;
import com.xykj.pojo.dto.NewsFlashDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassDescription: 证券快讯表Mapper层
 * @author:yzh
 * @create:2025/5/12 22:11
 **/
@Mapper
public interface NewsFlashMapper {

    /**
     * 查询按发布时间倒序的快讯列表，带分页
     */
    @Select("""
        SELECT
          title as title,
          content as content,
          type as type,
          publish_time as publishTime
        FROM news_flash
        WHERE is_deleted = 0
        ORDER BY publish_time DESC
        LIMIT #{offset}, #{limit}
        """)
    List<NewsFlashDto> selectLatest(
            @Param("offset") int offset,
            @Param("limit")  int limit
    );

    /**
     * 查询快讯总数，用于分页
     */
    @Select("SELECT COUNT(*) FROM news_flash WHERE is_deleted = 0")
    int countAll();

    /**
     * 爬虫存储数据
     * @param list
     */
    void batchInsert(List<NewsFlash> list);

    void batchDelete(@Param("ids") List<Long> ids);
    List<Long> selectExistingIds();
}
